<?php

namespace app\admin\model;

use think\Model;

/**
 * 官方消息
 * Class OfficialMessage
 * @package app\admin\model
 */
class OfficialMessage extends Model
{
    /**
     * 官方消息列表
     * @param $where
     * @param $page
     * @param $limit
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getOfficialMessageList($where, $page, $limit)
    {
        $data = self::where($where)
            ->page($page, $limit)
            ->order('create_time', 'desc')
            ->select();

        return $data ? $data->toArray() : [];
    }

    /**
     * 官方消息总数
     * @param array $where
     * @return int
     */
    public static function countOfficialMessage($where)
    {
        return self::where($where)->count();
    }

    /**
     * 指定官方消息
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function findOfficialMessage($where)
    {
        $info = self::where($where)->find();

        return $info ? $info->toArray() : [];
    }

    /**
     * 添加官方消息
     * @param $data
     * @return Article|Model
     */
    public static function createOfficialMessage($data)
    {
        return self::create($data);
    }

    /**
     * 更新官方消息
     * @param $data
     * @param $where
     * @return OfficialMessage
     */
    public static function updateOfficialMessage($data, $where)
    {
        return self::update($data, $where);
    }
}